package com.opensky.qatest.ui.page;

import junit.framework.Assert;

import org.openqa.selenium.support.ui.LoadableComponent;

import com.opensky.qatest.util.common.AssertReport;
import com.opensky.qatest.util.common.LogicUtils;
import com.opensky.qatest.util.selenium.WebDriverWrapper;

public class CheckoutPage extends LoadableComponent<CheckoutPage> implements IPage {

    // ************************ Locators ************************

    private static final String CHECKOUT_PAGE_URL = "https://opensky.com/checkout";

    private final WebDriverWrapper driver;

    public CheckoutPage(WebDriverWrapper driver) {
	this.driver = driver;
    }

    // ************************ Actions **************************

    @Override
    protected void load() {
	driver.get(CHECKOUT_PAGE_URL);
    }

    // ************************ Validations **************************

    @Override
    protected void isLoaded() throws Error {
	String url = driver.getCurrentUrl();
	Assert.assertTrue(AssertReport.wrongURL(CHECKOUT_PAGE_URL, url), LogicUtils.isURLEqual(CHECKOUT_PAGE_URL, url));
    }

    public boolean isPageLoaded() {
	return driver.waitAndVerifyURL(CHECKOUT_PAGE_URL);
    }
}
